package com.jmb.api.controller.permission;

import com.jmb.api.common.exception.LeaseException;
import com.jmb.api.common.result.Result;
import com.jmb.api.common.result.ResultCodeEnum;
import com.jmb.api.service.PermissionService;
import com.jmb.api.vo.permission.PermissionInfoVo;
import com.jmb.api.vo.permission.PermissionUpdateVo;
import com.jmb.api.vo.permission.PermissionVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "权限管理")
@RestController
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @Operation(summary = "权限管理新增")
    @PostMapping("save")
    public Result addPermission(@RequestBody  PermissionVo permissionVo) {
        permissionService.savePermission(permissionVo);
        return Result.ok();
    }
    @Operation(summary = "权限管理修改")
    @PostMapping("modify")
    public Result modifyPermission(@RequestBody PermissionUpdateVo permissionUpdateVo) {
        permissionService.updatePermission(permissionUpdateVo);
        return Result.ok();
    }
    @Operation(summary = "权限管理删除")
    @PostMapping("remove")
    public Result removePermission(@RequestParam Integer id) {
        if (id ==null){
            throw new LeaseException(ResultCodeEnum.WEB_API_ID_NOT_NULL);
        }
        permissionService.removeById(id);
        return Result.ok();
    }
    @Operation(summary = "权限管理列表")
    @GetMapping
    public Result<List<PermissionInfoVo>> getPermissionList() {
        List<PermissionInfoVo> list  = permissionService.getPermissionList(0);
        return Result.ok(list);
    }


}
